package cc.site.main.controller;

import cc.site.common.utils.R;
import cc.site.main.bean.TblKind;
import cc.site.main.service.TblKindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 种类 前端控制器
 * </p>
 *
 * @author yangruomao
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/kind")
@Api(tags = "种类管理")
public class TblKindController {

    @Autowired
    private TblKindService kindService;

    @GetMapping
    @ApiOperation("所有种类")
    public R list() {
        return R.ok().data("list",kindService.list());
    }

    @PutMapping
    @ApiOperation("编辑种类, id无效")
    public R update(@RequestBody TblKind kind) {
        kind.setId(null);
        kindService.updateById(kind);
        return R.ok();
    }

    @PostMapping
    @ApiOperation("添加种类")
    public R save(@RequestBody TblKind kind) {
        kindService.save(kind);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除种类")
    public R delete(@PathVariable("id") Integer id) {
        kindService.removeById(id);
        return R.ok();
    }

}
